import Vue from 'vue'
import Vuex from 'vuex'
import { getApiBaseUserInfo } from '@/api'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    searchVal: '',
    userInfo: null,
    // userInfo: {
    //   avatar: null,
    //   browse_count: 0,
    //   collect_count: 1,
    //   id: 1,
    //   nickname: null,
    //   phone: "18684850570",
    //   time: 1606906428,
    // }
    setting: null,
    // setting: {
    //   address: '成都',
    //   company: '公司名称',
    //   describe: '网站描述',
    //   id: 1,
    //   keyword: '关键字',
    //   logo:
    //     'http://m.huangxh.top\\uploadsadminarticle_thumb\\20210323\\50c014e68c540622b6eb16e6d90420d8.png',
    //   name: '就这租',
    //   phone: '18272716271',
    //   qr_code:
    //     'http://m.huangxh.top\\uploadsadminarticle_thumb\\20210323\\158a5621291d9bd3cd14c005848e3290.png',
    //   work_time: '工作时间  19-19',
    // },
  },
  getters: {
    _userInfo: state => {
      return state.userInfo;
    }
  },
  mutations: {
    setUserInfo (state, userInfo) {
      if (userInfo && userInfo.id) localStorage.setItem('id', userInfo.id)
      if (!userInfo) localStorage.removeItem('id')
      state.userInfo = userInfo
    },
    setSetting (state, setting) {
      state.setting = setting
    },
    setSearchVal (state, searchVal) {
      state.searchVal = searchVal
    },

  },
  actions: {
    getUserInfo ({ commit }, params) {
      getApiBaseUserInfo(params).then(res => {
        if (res.code === 200) {
          commit('setUserInfo', res.data)
        }
      })
    }
  },
  modules: {
  }
})
